// 自己些的 define myrequire module exports
// 逻辑简单，去除细节，保留整体设计
// 参考cordova.js中的设计

var modules = {};

var define = function(id, factory) {
    modules[id] = {
        "id":id,
        "factory":factory
    }
}

var build = function(module) {
    console.log('build,id=' + module.id);
    module.exports = {};
    module.factory(myrequire, module.exports, module);
    return module.exports;
}

var myrequire = function(id) {
    console.log('myrequire,id=' + id);
    if (!modules[id]) {
        console.log('no this module id=' + id);
    }
    return build(modules[id]);
}

define('myTxt',function(localRequire,exports,module){
    exports.aa = 'myTxt';
});

define('myLog', function(localRequire, exports, module) {
    var txt = localRequire('myTxt');
    exports.fn = function() {
        console.log(txt.aa);
    }
});

var x = myrequire('myLog');
x.fn();